# 2  编写一个装饰器，能记录其他函数调用的日志，将日志写入到文件中；
import datetime
import time


def wrapper(func):
    def inner(*args, **kwargs):
        timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ret = func(*args, **kwargs)
        f.write(f'{timestamp} {func.__name__}{args} -> {ret}\n')
        return ret
    return inner

@wrapper
def func1(x, y):
    time.sleep(0.1)
    return x + y

@wrapper
def func2(a, b):
    time.sleep(0.5)
    return a * b


if __name__ == '__main__':
    with open('log.txt', mode='w', encoding='utf-8') as f:
        func1(1, 2)
        func2(3, 4)
